<?php

class Home_BuddyController extends Ext_Controller_Action_Front
{
    public function init()
    {
        parent::init();
    }

    public function myFriendsAction()
    {
        $userId = Ext_Auth_Front::getInstance()->getIdentity();
        
        $author = Ext_User::getInstance()->show($userId)->buildAvatar()->buildUrl();
        
        $count = App_Model_Buddy::getInstance()->getMyBuddyCount($userId);
        $list  = App_Model_Buddy::getInstance()->getMyBuddyList($userId);
        $adapter = new Zend_Paginator_Adapter_DbSelect($list);
        $adapter->setRowCount($count);
        $paginator = new Zend_Paginator($adapter);
        $paginator
              //->setCurrentPageNumber(1)
              ->setItemCountPerPage(12)
              ->setCurrentPageNumber($this->_getParam('page'))
            //->setDefaultPageRange(20)
            ;
        $friends = array();
        foreach ($paginator as $key=>$item)
        {
            $_userId = $item['buddyUserId'];
            
            $buddyCheck = new Ext_Buddy_Check($_userId);
            $isMyBuddy  = $buddyCheck->isMyBuddy();
            
            $user = Ext_User::getInstance()->show($_userId)->buildAvatar()->buildUrl();
            
            $friends[] = array('isMyBuddy'=>$isMyBuddy, 'user'=>$user);
        }
        
        $this->view->author    = $author;
        $this->view->friends   = $friends;
        $this->view->paginator = $paginator;        
    }
    
}

?>